All Questions
11 questions
3votes
4answers
600views
Why is "dependency injection" ok, but not "the opposite of preserve whole object (pass required parameters only)"?
According to Why should I use dependency injection?, "dependency injection" has some advantages, for example: "Non dependency injection" version: public class Client{ private ...
0votes
0answers
205views
How to handle dependency injection in a library to avoid frequent breaking changes?
Let's say I have a C# .NET library with the following classes: public class FooService { private readonly IDependencyA a; public FooService(IDependencyA a) { this.a = a; } ...
0votes
3answers
328views
How to choose between these different options for communicating between objects?
I have a few objects that should communicate between each other. I also want to have my code unit tested. I am questioning how I should handle their communication: Should I make one instantiate the ...
-1votes
3answers
876views
Factory needs list of available objects. Should it be static or not?
I have a list of IReader that I read at the beginning of my program. Later on I need ReaderFactory to get appropriate IReader based on Extensions it can use. The problem is the factory needs to know ...
20votes
5answers
7kviews
What are the benefits of dependency injection in cases where almost everyone needs access to a common data structure?
There are plenty of reasons why globals are evil in OOP. If the number or size of the objects needing sharing is too large to be efficiently passed around in function parameters, usually everyone ...
6votes
1answer
4kviews
PHP: Injecting the same database connection into multiple objects
Suppose that there are two classes that define objects of vastly different function such that in the datastore, the information they require is divided into two separate databases. For example, the ...
2votes
1answer
242views
Injection, strategies and OO
I'm working on refactoring a project. The business logic looks very much like using the Strategy pattern would be very beneficial, because depending on the values of three properties (let's say age, ...
-1votes
1answer
512views
Multiple method calls in the constructor and dependency injection
I was asked to refactor some almost ureadable spaghetti code into object-oriented architecture. I have some doubts regarding a class that I designed. Here is the class' skeleton: require_once 'inc/...
4votes
2answers
392views
Sharing state with dependencies - Object-Oriented Design
Suppose that I define two interfaces below: public interface IReader { void Read(string bookName); } public interface IWriter { void Write(string bookName); } Now I want to implement IReader ...
13votes
6answers
3kviews
Questioning one of the arguments for dependency injection frameworks: Why is creating an object graph hard?
Dependency injection frameworks like Google Guice give the following motivation for their usage (source): To construct an object, you first build its dependencies. But to build each dependency, you ...
17votes
2answers
31kviews
Factory Pattern and/or Dependency Injection? [duplicate]
I understand the concept and can use both the Factory Pattern and Dependency Injection, however they seem a little at odds with each other conceptually. Is it a case of using one over the other? Or ...